package com.nengchuan.eic.nceconomy.aspect;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;


/**
 * @author luo_zm
 * @DESCRIPTION 对于页面中请求的参数做统一处理
 * @create 2020/3/13 17:55
 */
@Component
@Aspect
@Order(10)
public class RequsetParamAop {
    @Autowired
    private HttpServletRequest request;

    private final static Logger logger = LoggerFactory.getLogger(RequsetParamAop.class);


    @Pointcut(
            value = "execution(* com.nengchuan.eic.nceconomy.controller..*(..))"

    )
    public void requestParamCut() {
    }

    @Pointcut(
            value = "execution(* com.nengchuan.eic.nceconomy.dao..*(..))"

    )
    public void dao() {
    }

    @Before(
            value = "requestParamCut()"
    )
    public void flowPointCut(JoinPoint point) {

    }

    @Around(value = "requestParamCut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        long time=System.currentTimeMillis();
        logger.info("开始调用controller方法"+pjp.getSignature().getName());
        Object proceed = pjp.proceed();//执行目标方法
        logger.info(pjp.getSignature().getName()+"方结束调用controller方法耗时:"+(System.currentTimeMillis()-time));
        return proceed;
    }

    @Around(value = "dao()")
    public Object aroundDao(ProceedingJoinPoint pjp) throws Throwable {
        long time=System.currentTimeMillis();
        logger.info("开始调用dao方法"+pjp.getSignature().getName());
        Object proceed = pjp.proceed();//执行目标方法
        logger.info(pjp.getSignature().getName()+"方结束调用dao方法耗时:"+(System.currentTimeMillis()-time));
        return proceed;
    }

}
